package kr.bae.androidcomplete01.chapter07;

import kr.bae.androidcomplete01.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class DrawBitmapEx extends Activity {
	float cx = 0;
	float cy = 0;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new MyBitmap(this));
	}

	class MyBitmap extends View {
		Bitmap bit;

		public MyBitmap(Context context) {
			super(context);
			bit = BitmapFactory.decodeResource(getResources(),
					R.drawable.harubang);
		}

		@Override
		protected void onDraw(Canvas canvas) {
			super.onDraw(canvas);
			/*canvas.drawBitmap(bit, 10, 10, null);
			canvas.drawBitmap(bit, null, new Rect(120, 10, 170, 85), null);
			canvas.drawBitmap(bit, new Rect(30, 30, 70, 80), new Rect(180, 10,
					180 + 80, 10 + 100), null);*/
			canvas.drawBitmap(bit, cx, cy, null);
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			switch (event.getAction()) {
			case MotionEvent.ACTION_DOWN:
				
				cx = event.getX();
				cy = event.getY();
				break;
			case MotionEvent.ACTION_MOVE:
				cx = event.getX();
				cy = event.getY();
				break;
			default:
				break;
			}
			invalidate();
			return super.onTouchEvent(event);
		}
		
		

	}
}
